package etxt2db.annotators;

import java.io.IOException;
import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import edu.cmu.minorthird.text.Annotator;
import edu.cmu.minorthird.text.MonotonicTextLabels;
import edu.cmu.minorthird.text.Span;
import edu.cmu.minorthird.text.TextLabels;
import etxt2db.api.ClassificationModel;

public class HMMClassificationModel  extends ClassificationModel implements Serializable {
	private static final long serialVersionUID = -5187038352307612626L;
	protected Set<Set<String>> compatibleAttributes = new HashSet<Set<String>>();
	Annotator ann;
	
	public HMMClassificationModel(TextLabels trainingFile,Set<Set<String>> compatibleAttributes) throws ParseException, IOException{
		this.compatibleAttributes = compatibleAttributes;
		ann = doTraining(trainingFile);
	}
	
	
	protected Annotator doTraining (TextLabels labels) throws IOException, ParseException{
		OverlapedTagClassificationModel result = new OverlapedTagClassificationModel();
		for(Set<String> setStr : compatibleAttributes){
			List<String> listStr = new ArrayList<String>(setStr);
			// Train the Annotator
			result.addAnnotator(new LingpipeHMMClassificationModel(labels,listStr));
		}
		return result;
	}
	
	public void annotate(MonotonicTextLabels arg0) {
		ann.annotate(arg0);	
	}

	public TextLabels annotatedCopy(TextLabels arg0) {
		return ann.annotatedCopy(arg0);
	}

	public String explainAnnotation(TextLabels arg0, Span arg1) {
		return null;
	}

}
